import { getPersonList,getCarList,getSanitationStationList } from '@/api/bigScreen.js';

const personStatus = {
  "-1": {
    name: "异常",
    color: "#f57f17"
  },
  0: {
    name: "正常",
    color: "#00e676"
  },
  1: {
    name: "迟到",
    color: "#ffff00"
  },
  2: {
    name: "旷工",
    color: "#ff3d00"
  },
  3: {
    name: "请假",
    color: "#2962ff"
  },
  4: {
    name: "异常",
    color: "#f57f17"
  },
  5: {
    name: "休息",
    color: "#808080"
  }
}

const carStatus = {
  0: {
    name: "正常",
    color: "#00e676"
  },
  1: {
    name: "冻结",
    color: "#ff3d00"
  },
  2: {
    name: "空闲",
    color: "#2962ff"
  },
  3: {
    name: "维修",
    color: "#f57f17"
  }
};

const sanitationStationStatus = {
  0: {
    name: "正常",
    color: "#00e676"
  },
  1: {
    name: "冻结",
    color: "#ff3d00"
  }
}

const getColorOptions = (options, targetKey) => {
  return Object.keys(options).reduce((acc, key) => {
    const data = options[key];
    const value = data?.[targetKey];
    acc[key] = value;
    return acc;
  }, {});
};
export const getPersonEquipmentOptions = () => ({
  1: {
    name: "人员",
    request: getPersonList,
    value: 'employees',
    options: [
      {
        name: '姓名',
        value: 'name',
        setColor: () => '#fff',
      },
      {
        name: '手机号',
        value: 'phone',
        setColor: () => '#1de9b6',
      },
      {
        name: '状态',
        value: 'status',
        format: (value) => {
          const names = getColorOptions(personStatus, 'name');
          return names?.[value] ?? '';
        },
        setColor: (row) => {
          const {status} = row;
          const colors = getColorOptions(personStatus, 'color');
          return colors?.[status] ?? '#fff';
        },
      },
    ],
  },
  2: {
    name: "车辆",
    request: getCarList,
    value: 'cars',
    options: [
      {
        name: '车牌',
        value: 'carNumber',
        setColor: () => '#fff',
      },
      {
        name: '驾驶人',
        value: 'driverName',
        setColor: () => '#1de9b6',
      },
      {
        name: '状态',
        value: 'status',
        format: (value) => {
          const names = getColorOptions(carStatus, 'name');
          return names?.[value] ?? '';
        },
        setColor: (row) => {
          const {status} = row;
          const colors = getColorOptions(carStatus, 'color');
          return colors?.[status] ?? '#fff';
        },
      },
    ],
  },
  3: {
    name: "环卫站",
    request: getSanitationStationList,
    value: 'platforms',
    options: [
      {
        name: '名称',
        value: 'name',
        setColor: () => '#fff',
      },
      {
        name: '已用容量',
        value: 'usedCapacity',
        format: (value) => {
          return `${value || 0}%`;
        },
        setColor: () => '#1de9b6',
      },
      {
        name: '状态',
        value: 'status',
        format: (value) => {
          const names = getColorOptions(sanitationStationStatus, 'name');
          return names?.[value] ?? '';
        },
        setColor: (row) => {
          const {status} = row;
          const colors = getColorOptions(sanitationStationStatus, 'color');
          return colors?.[status] ?? '#fff';
        },
      },
    ],
  }
})
